<header class="es-header navbar">
  <div class="navbar-header">
    <div class="visible-xs  navbar-mobile">
      <a href="javascript:;" class="navbar-more js-navbar-more">
        <i class="es-icon es-icon-menu"></i>
      </a>
      <div class="html-mask"></div>
      <div class="nav-mobile">
        <form class="navbar-form" action="{{ path('search') }}" method="get">
          <div class="form-group">
            <input class="form-control" placeholder="{{'搜索'|trans}}" name="q">
            <button class="button es-icon es-icon-search"></button>
          </div>
        </form>

        <ul class="nav navbar-nav">
          {% set navigations = data('NavigationsTree', {}) %}
          {% include 'TopxiaWebBundle:Default:top-navigation.html.twig' with {navigations: navigations,siteNav: siteNav|default(null), isMobile: true} %}
        </ul>
      </div>
    </div>
    <a href="{{ path('homepage') }}" class="navbar-brand">
      {% if setting('site.logo') %}
        <img src="{{ filepath('../' ~ setting('site.logo'),'') }}">
      {% else %}
        {{ setting('site.name', 'EDUSOHO') }}
      {% endif %}
    </a>
  </div>
  <nav class="collapse navbar-collapse">
    <ul class="nav navbar-nav clearfix hidden-xs " id="nav">
      {% include 'TopxiaWebBundle:Default:top-navigation.html.twig' with {navigations: navigations,siteNav: siteNav|default(null), isMobile: false} %}
    </ul>
    <div class="navbar-user {% if setting('esBar.enabled', 0) %} left {% endif %}">
      <ul class="nav user-nav">
        {% if app.user %}
        <li class="user-avatar-li nav-hover">
          <a href="javascript:;" class="dropdown-toggle">
            <img class="avatar-xs" src="{{ filepath(app.user.smallAvatar, 'avatar.png') }}">
          </a>
          <ul class="dropdown-menu" role="menu">
            <li role="presentation" class="dropdown-header">{{ app.user.nickname }}</li>
            <li><a href="{{ path('user_show', {id:app.user.id}) }}"><i class="es-icon es-icon-person"></i>{{'个人主页'|trans}}</a></li>
            <li><a href="{{ path('settings') }}"><i class="es-icon es-icon-setting"></i>{{'个人设置'|trans}}</a></li>
            <li class="hidden-lg">
              <a href="{{ path('my') }}">
                <i class="es-icon es-icon-eventnote"></i>{% if 'ROLE_TEACHER' in app.user.roles %}{{'我的教学'|trans}}{% else %}{{'我的学习'|trans}}{% endif %}
              </a>
            </li>
            <li><a href="{% if setting('coin.coin_enabled') %}{{path('my_coin')}}{% else %}{{path('my_bill')}}{% endif %}"><i class="es-icon es-icon-accountwallet"></i>{{'账户中心'|trans}}</a></li>

            {% if has_permission('admin') %}<li><a href="{{ path('admin') }}"><i class="es-icon es-icon-dashboard"></i>{{'管理后台'|trans}}</a></li>
            {% endif %}

            <li class="hidden-lg"><a href="{{ path('notification') }}"><span class="pull-right num">{% if app.user.newNotificationNum > 0 %}{{ app.user.newNotificationNum }}{% endif %}</span><i class="es-icon es-icon-notificationson"></i>{{'通知'|trans}}</a></li>
            <li class="hidden-lg"><a href="{{ path('message') }}"><span class="pull-right num">{% if app.user.newMessageNum > 0 %}{{ app.user.newMessageNum }}{% endif %}</span><i class="es-icon es-icon-mail"></i>{{'私信'|trans}}</a></li>
            <li><a href="{{ path('logout') }}"><i class="es-icon es-icon-power"></i>{{'退出登录'|trans}}</a></li>
          </ul>
        </li>
        <li class="visible-lg">
          <a href="{{ path('my') }}">
            {% if 'ROLE_TEACHER' in app.user.roles %}
              {{'我的教学'|trans}}
            {% else %}
              {{'我的学习'|trans}}
            {% endif %}
          </a>
        </li>
        <li class="visible-lg nav-hover">

          {% if setting('esBar.enabled', 0) and app.user.newMessageNum > 0 %}
            <a class="hasmessage"><i class="es-icon es-icon-mail"></i><span class="dot"></span></a>
          {% elseif ( not setting('esBar.enabled', 0)) and ( app.user.newNotificationNum > 0 or app.user.newMessageNum > 0) %}
            <a class="hasmessage"><i class="es-icon es-icon-mail"></i><span class="dot"></span></a>
          {% else %}
            <a><i class="es-icon es-icon-mail"></i></a>
          {% endif %}

          <ul class="dropdown-menu" role="menu">
            {% if not setting('esBar.enabled', 0) %}
              <li>
                <a href="{{ path('notification') }}">
                  <span class="pull-right num">{% if app.user.newNotificationNum > 0 %}{{ app.user.newNotificationNum }}{% endif %}</span>
                  <i class="es-icon es-icon-notificationson"></i>{{'通知'|trans}}
                </a>
              </li>
            {% endif %}
            <li>
              <a href="{{ path('message') }}">
                <span class="pull-right num">{% if app.user.newMessageNum > 0 %}{{ app.user.newMessageNum }}{% endif %}</span>
                <i class="es-icon es-icon-mail"></i>{{'私信'|trans}}
              </a>
            </li>
          </ul>
        </li>
        {% else %}
        <li class="user-avatar-li nav-hover visible-xs">
          <a href="javascript:;" class="dropdown-toggle">
            <img class="avatar-xs" src="{{ asset('assets/img/default/avatar.png') }}">
          </a>
          <ul class="dropdown-menu" role="menu">
            <li><a href="{{ path('login', {goto:_target_path|default(app.request.server.get('REQUEST_URI'))}) }}">{{'登录'|trans}}</a></li>
            <li><a href="{{ path('register', {goto:_target_path|default(app.request.server.get('REQUEST_URI'))}) }}">{{'注册'|trans}}</a></li>
          </ul>
        </li>
        <li class="hidden-xs"><a href="{{ path('login', {goto:_target_path|default(app.request.server.get('REQUEST_URI'))}) }}">{{'登录'|trans}}</a></li>
        <li class="hidden-xs"><a href="{{ path('register', {goto:_target_path|default(app.request.server.get('REQUEST_URI'))}) }}">{{'注册'|trans}}</a></li>
        {% endif %}
        {# {% include 'TopxiaWebBundle:Default:switch-language.html.twig' %} #}
      </ul>
      <form class="navbar-form navbar-right hidden-xs hidden-sm" action="{{ path('search') }}" method="get">
        <div class="form-group">
          <input class="form-control js-search" name="q" placeholder="{{'搜索'|trans}}">
          <button class="button es-icon es-icon-search"></button>
        </div>
      </form>
    </div>
  </nav>
</header>